import java.sql.*;
import java.util.*;

public class H2Test {

    public static void main(String[] args) throws Exception {
        //以嵌入式内存模式工作，建个简单的表 
        Connection conn = DriverManager.getConnection("jdbc:h2:F:\\H2\\db\\test");
//        PreparedStatement stmt = conn.prepareStatement("CREATE TABLE cc (GUID varchar(40) PRIMARY KEY,Data int,AddTime datetime,XM varchar(100))");
//        stmt.execute();
//        Random rand = new Random();
//
//        //精度要求不高，就用这个计时吧
//        long start = System.currentTimeMillis();
//        stmt = conn.prepareStatement("INSERT INTO cc VALUES (RANDOM_UUID(), ?, NOW(), ?)");
//        for(int i = 0;i < 10000;++i){
//            stmt.setInt(1, rand.nextInt());
//            stmt.setString(2, String.valueOf(i));
//            stmt.execute();
//        }
//        long duration = System.currentTimeMillis() - start;
//        conn.close();

//        System.out.println("Finished in " + duration + " ms");

        PreparedStatement stmt = conn.prepareStatement("select * from cc");
        ResultSet resultSet = stmt.executeQuery();
        while (resultSet.next()) {
            System.out.println(resultSet.getString("GUID")+","+resultSet.getInt("Data")+","+resultSet.getString("XM"));
        }
        conn.close();
    }

} 